function foreach(len, cb) {
  var i = 0;
  function handleIndex(index) {
    return cb(index);
  }
  for (; i < len; i++) handleIndex(i);
}
function $(name) {
  var el = document.getElementsByClassName(name);
  return el.length ? el[0] : null;
}

function fill0(v) {
  return (v < 10 ? '0' : '') + v;
}
function dateObject(time) {
  var date = time ? new Date(time) : new Date();
  return {
    y: date.getFullYear(),
    M: fill0(date.getMonth() + 1),
    d: fill0(date.getDate()),
    h: fill0(date.getHours()),
    m: fill0(date.getMinutes()),
    s: fill0(date.getSeconds()),
    w: date.getDay()
  };
}
